﻿@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/Main.cshtml";
}
<div class="row">
    <div class="span10"></div>
    <div class="span2">
        <a href="#" class="btn" id="btnAddModal">Add</a>
    </div>
</div>
<table class="table table-hover">
    <thead>
        <tr>
            <th>编码</th>
            <th>名称</th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in (List<ASoft.Web.Base.AUser>)ViewData["grid"])
        {
            <tr>
                <td>@item.Code</td>
                <td>@item.CName</td>
                <td><a href="#" onclick="update('@item.AUserId','@item.Code','@item.CName','')"><i class="icon-wrench"></i></a></td>
                <td><a href="#" onclick="del('@item.AUserId')"><i class="icon-trash"></i></a></td>
            </tr>
        }
    </tbody>
</table>
<div class="row">
    @Html.Partial("TablePager")
</div>
<div id="addModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">用户维护</h3>
    </div>
    <div class="modal-body" id="detailDiv">
        <div class="form-horizontal">
            <div class="control-group">
                <label class="control-label" for="Code">编码</label>
                <div class="controls">
                    <input type="text" id="Code" name="Code" maxlength="20">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="CName">名称</label>
                <div class="controls">
                    <input type="text" id="CName" name="CName" maxlength="20">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="CPassword">密码</label>
                <div class="controls">
                    <input type="password" id="CPassword" name="CPassword" maxlength="20">
                </div>
            </div>
            <input type="hidden" id="AUserId" name="AUserId" />
        </div>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
        <button class="btn btn-primary" id="btnSave">保存</button>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#btnSave").click(function () {
            var auserid = $("#AUserId").val();
            var actionName = "update";
            if (auserid == "0") {
                actionName = "add";
            }
            $.myjs.ajax(actionName, "detailDiv", function () { window.location.reload(); });
        });

        $("#btnAddModal").click(function () {
            setMoalValue(0, '', '', '');
            $('#myModalLabel').text("添加用户");
            $('#addModal').modal('show')
        });
    });

    function del(auserid) {
        setMoalValue(auserid, "", "", "");
        $.myjs.ajax("delete", "detailDiv", function () { window.location.reload(); });
    }

    function update(auserid, code, cname, cpassword) {
        setMoalValue(auserid, code, cname, cpassword);
        $('#myModalLabel').text("修改用户");
        $('#addModal').modal('show')
    }

    function setMoalValue(auserid, code, cname, cpassword) {
        $("#AUserId").val(auserid);
        $("#Code").val(code);
        $("#CName").val(cname);
        $("#CPassword").val(cpassword);
    }
</script>
